package com.bilibili.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bilibili.entity.CommonResult;
import com.bilibili.entity.Page;
import com.bilibili.entity.Video;
import com.bilibili.service.LikeSelectVideoService;
import com.bilibili.service.impl.LikeSelectVideoServiceImpl;

@WebServlet("/selectLikeVideo.do")
public class LikeSelectVideoServlet extends HttpServlet {
	
	private LikeSelectVideoService lsvs=new LikeSelectVideoServiceImpl();
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("application/json;charset=utf-8");
		String likeName=request.getParameter("likeName");
		int pageNum,pageSize;
		try {
			pageNum=Integer.parseInt(request.getParameter("pageNum"));
		} catch (Exception e) {
			// TODO: handle exception
			pageNum=1;
		}
		try {
			pageSize=Integer.parseInt(request.getParameter("pageSize"));
		} catch (Exception e) {
			// TODO: handle exception
			pageSize=10;
		}
		Page<Video> videos=lsvs.getLikeSelectVideo(likeName,pageNum,pageSize);
		
		CommonResult cr=new CommonResult();
		if(videos.getData().size() == 0) {
			cr.setCode(409);
			cr.setMassage("default");
			cr.setData("");
		}else {
			cr.setCode(200);
			cr.setMassage("success");
			cr.setData(videos);
		}
		response.getWriter().write(cr.toJSONString());
	}

}
